﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DimensionAddIn
{
    public class DocValueTable
    {
        public Dictionary<string, object> ValueMap { get; set; }

        public DocValueTable()
        {
            ValueMap = new Dictionary<string, object>(); 
        }

        public void SetValue(string path, object value)
        {
            if (!ValueMap.ContainsKey(path))
            {
                ValueMap.Add(path, value);
            }
            else
            {
                ValueMap[path] = value;
            }
        }

        public object GetValue(string path)
        {
            return ValueMap[path];
        }

        public string Dump()
        {
            StringBuilder builder = new StringBuilder();
            bool isFirst = true;
            foreach(string key in ValueMap.Keys)
            {
                if (isFirst)
                {
                    builder.AppendFormat("{0},{1}", key, ValueMap[key]);
                    isFirst = false;
                }
                else
                {
                    builder.AppendFormat(",{0},{1}", key, ValueMap[key]);
                }
            }
            return builder.ToString();
        }
    }
}
